package com.yuanyu.server.impl;



import com.yuanyu.common.util.CopyUtil;
import com.yuanyu.common.util.main.List1_Become_List2_Util;
import com.yuanyu.mapper.mysqlMapper.StaffMapper;
import com.yuanyu.model.dto.MainTableDTO;
import com.yuanyu.model.entity.MainTable;
import com.yuanyu.server.IStaffSever;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class StaffSeverImpl implements IStaffSever {
    @Autowired
    private StaffMapper staffMapper;


    @Override
    public List<MainTableDTO> queryPaginatedData(String process,Integer page) {
        List<MainTable> mainTables = new ArrayList<>();
        Integer number = (page - 1) * 10;
        switch (process){
            case "1":
                mainTables = staffMapper.queryPaginatedData1(number);
                break;
            case "2":
                mainTables = staffMapper.queryPaginatedData2(number);
                break;
            case "3":
                mainTables = staffMapper.queryPaginatedData3(number);
                break;
            case "4":
                mainTables = staffMapper.queryPaginatedData4(number);
                break;
            case "5":
                mainTables = staffMapper.queryPaginatedData5(number);
                break;
            case "6":
                mainTables = staffMapper.queryPaginatedData6(number);
                break;
            case "7":
                mainTables = staffMapper.queryPaginatedData7(number);
                break;
            case "8":
                mainTables = staffMapper.queryPaginatedData8(number);
                break;
            case "9":
                mainTables = staffMapper.queryPaginatedData9(number);
                break;
            case "10":
                mainTables = staffMapper.queryPaginatedData10(number);
                break;
        }
        return List1_Become_List2_Util.mainTableBecomeMainTables(mainTables);
    }

    @Override
    public Integer queryPaginatedPage(String process) {
        Integer i = null;
        switch (process){
            case "1":
                i = staffMapper.selPageTable1();
                break;
            case "2":
                i = staffMapper.selPageTable2();
                break;
            case "3":
                i = staffMapper.selPageTable3();
                break;
            case "4":
                i = staffMapper.selPageTable4();
                break;
            case "5":
                i = staffMapper.selPageTable5();
                break;
            case "6":
                i = staffMapper.selPageTable6();
                break;
            case "7":
                i = staffMapper.selPageTable7();
                break;
            case "8":
                i = staffMapper.selPageTable8();
                break;
            case "9":
                i = staffMapper.selPageTable9();
                break;
            case "10":
                i = staffMapper.selPageTable10();
                break;
        }
        return i;
    }

    @Override
    public MainTableDTO queryByCase(String Case) {
        MainTable mainTable = staffMapper.queryByCase(Case);
        MainTableDTO mainTableDTO = new MainTableDTO();
        CopyUtil.copyClass(mainTable, mainTableDTO);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        mainTableDTO.setSpawn_time(mainTable.getSpawn_time().format(formatter));
        if (mainTable.getStart_time()!=null){
            mainTableDTO.setStart_time(mainTable.getStart_time().format(formatter));
        }else {
            mainTableDTO.setStart_time("未开工");
        }
        if (mainTable.getEnd_time()!=null){
            mainTableDTO.setEnd_time(mainTable.getEnd_time().format(formatter));
        }else {
            mainTableDTO.setEnd_time("未完工");
        }
        System.out.println("mainTableDTO = " + mainTableDTO);
        return mainTableDTO;
    }

}
